<?php

/*
 * Action - Attack - Looter 5$
 *
 * +2 cards
 * Each other player gains a Ruins. You may play a Cultist from your hand
 * When you trash this, +3 cards
 */

class Cultist extends Card implements iAction, iKingdom, iDarkAges, iAttack {

    public function __construct() {
        parent::__construct("Cultist", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+2 cards",
            "Each other player gains a Ruins. You may play a Cultist from your hand.",
            "When you trash this, +3 cards");
    }

    public function trash(Game $game, $name) {
        $drawed_cards = $game->drawCards(3, $name);
        ScreenDisplay::addScreenMessage($game, true, "draw " . nicePrint($drawed_cards), "draws " . sizeof($drawed_cards) . " cards", $name);
        $game->setTempCard($this);
        $game->cardTrashFinished($name);
    }

    public function play(Game $game, $isRealCard) {
        $drawed_cards = $game->drawCards(2);
        ScreenDisplay::addScreenMessage($game, true, "draw " . nicePrint($drawed_cards), "draws " . sizeof($drawed_cards) . " cards");

        $names = $game->getOtherPlayersNames();
        foreach ($names as $name) {
            $r = new Ruin();
            $ruin = $game->moveCardFromPileToPile($r, BoardCards, DiscardPile, $name);
            if ($ruin) {
                ScreenDisplay::addScreenMessage($game, true, "gain  " . nicePrint($ruin), "gains ".ScreenDisplay::$LMSG, $name);
            } else {
                ScreenDisplay::addScreenMessage($game, true, "gain  nothing", "gains nothing", $name);
            }
        }

        $playHand = $game->getPlayHand();
        $cultistFound = false;
        foreach ($playHand as $card) {
            if ($card instanceof Cultist) {
                $cultistFound = true;
                break;
            }
        }
        
        if ($cultistFound) {
            $options = array(new Option(1, "Yes"), new Option(2, "No"));
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Play another Cultist?");
            $answer = $output[0];
            if ($answer == "Yes") {
                ScreenDisplay::addScreenMessage($game, true, "play ".  nicePrint($this), "plays ".  nicePrint($this));
                $cultist = $game->moveCardFromPileToPile("Cultist", PlayHand, PlayArea);
                 if ($cultist) {
                     $game->pushCardToStack($cultist);
                 }
            } else {
                // do nothing
            }
        }
		$game->cardActionFinished();
        return true;
    }

    public function boardSetup(Game $game) {
        $game->addRuins();
        return true;
    }
}

?>